<template>
  <div>
    <h1 class="center">欢迎来到注册页面</h1>
    <!-- <div>
      <span>账号:</span>
      <input type="text" placeholder="请输入账号" v-model="user.phone" />
    </div>

    <div>
      <span>昵称:</span>
      <input type="text" placeholder="请输入昵称" v-model="user.nickname" />
    </div>

    <div>
      <span>密码:</span>
      <input type="password" placeholder="请输入密码" v-model="user.password" />
    </div>
    <button @click="register">提交</button> -->

     <van-form @submit="register">
      <van-field
        v-model="user.phone"
        name="账号"
        label="账号"
        placeholder="账号"
        :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
        v-model="user.nickname"
        type="password"
        name="昵称"
        label="昵称"
        placeholder="昵称"
        :rules="[{ required: true, message: '请填写昵称' }]"
      />
      <van-field
        v-model="user.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 8px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import {reqregister} from "../../http/http"
export default {
  data() {
    return {
      user: {
        phone: "",
        nickname: "",
        password: "",
      },
    };
  },
  methods: {
    register() {
      reqregister(this.user).then((res) => {
        if(res.data.code==200){
            alert(res.data.msg)
             this.$router.push("/index/login")
        }else{
            alert(res.data.msg)
        }
      });
    },
  },
};
</script>

<style scoped>
.center {
  text-align: center;
}
div {
  margin: 20px 0;
}
</style>